package com.zhiche.lisa.bms.service.fee.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.zhiche.lisa.bms.dao.mapper.fee.FeeTypeMapper;
import com.zhiche.lisa.bms.dao.model.fee.FeeType;
import com.zhiche.lisa.bms.service.fee.FeeTypeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 费用类型 服务实现类
 * </p>
 *
 * @author qichao
 * @since 2018-09-07
 */
@Service
public class FeeTypeServiceImpl extends ServiceImpl<FeeTypeMapper, FeeType> implements FeeTypeService {
    /**
     * 根据费用名称查询费用类型表
     *
     * @param typeName
     */
    @Override
    public FeeType queryCostMidByBillId(String typeName) {
        FeeType cn = new FeeType();
        Wrapper<FeeType> ew = new EntityWrapper<>();
        if (!Objects.isNull(typeName) && !Strings.isNullOrEmpty(typeName)) {
            ew.like("type_name", typeName).eq("is_payable", 1).eq("is_receivable", 0);
            cn = this.selectOne(ew);
        }
        return cn;
    }

    /**
     * 获取费用类型信息
     *
     * @return
     */
    @Override
    public Map<String, Long> queryFeeTypeByTypeName() {
        Map<String, Long> map = Maps.newHashMap();
        List<FeeType> feeTypeList = new ArrayList<>();
        EntityWrapper<FeeType> ew = new EntityWrapper<>();
        ew.eq("is_payable", 0);
        ew.eq("is_receivable", 1);
        feeTypeList = baseMapper.selectListNoTenant(ew);
        for (int i = 0; i < feeTypeList.size(); i++) {
            map.put(feeTypeList.get(i).getTypeName(), feeTypeList.get(i).getId());
        }
        return map;
    }
}
